package com.snail.config;

import com.snail.constants.RabbitMqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Monica
 * @description
 * @date 2025/8/13 18:03
 */
@Configuration
public class MediaRabbitCustomConfig {



    @Bean
    public MessageConverter messageConverter() {
        // 1.定义消息转换器
        Jackson2JsonMessageConverter jjmc = new Jackson2JsonMessageConverter();
        // 2.配置自动创建消息id，用于识别不同消息，也可以在业务中基于ID判断是否是重复消息
        jjmc.setCreateMessageIds(true);
        return jjmc;
    }
    @Bean
    public Queue mediaMergeQueue() {
        // 持久化队列
        return new Queue(RabbitMqConstants.MINIO_MERGE_QUEUE, true);
    }

    @Bean
    public DirectExchange mediaMergeExchange() {
        return new DirectExchange(RabbitMqConstants.MINIO_MERGE_EXCHANGE, true, false);
    }

    @Bean
    public Binding bindMediaQueue(Queue mediaMergeQueue, DirectExchange mediaMergeExchange) {
        return BindingBuilder.bind(mediaMergeQueue).to(mediaMergeExchange).with(RabbitMqConstants.MINIO_MERGE_ROUTING_KEY);
    }


    @Bean
    public Queue mediaReviewQueue() {
        // 持久化队列
        return new Queue(RabbitMqConstants.MINIO_REVIEW_QUEUE, true);
    }

    @Bean
    public DirectExchange mediaReviewExchange() {
        return new DirectExchange(RabbitMqConstants.MINIO_REVIEW_EXCHANGE, true, false);
    }

    @Bean
    public Binding bindMediaReviewQueue(Queue mediaReviewQueue, DirectExchange mediaReviewExchange) {
        return BindingBuilder.bind(mediaReviewQueue).to(mediaReviewExchange).with(RabbitMqConstants.MINIO_REVIEW_ROUTING_KEY);
    }
}
